#!/usr/bin/env python

def combination(nums, k):
    def _backtracking(nums, k, result, index, alist):
        if len(alist) == k:
            result.append(alist[:])
            return
        
        for i in range(index, len(nums)):
            alist.append(nums[i])
            _backtracking(nums, k, result, i + 1, alist)
            alist.pop()

    ans = []
    _backtracking(nums, k, ans, 0, [])
    return ans


if __name__ == "__main__":
    print(combination([i for i in range(1, 5)], 2))